package com.wwwc.index.web.servlet;

import java.io.*;
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletRequestWrapper;
import java.net.*;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;

import com.wwwc.util.web.*;
//import com.wwwc.index.web.database.*;
import com.wwwc.index.web.ejb.database.*;

public class PageColorServlet extends HttpServlet {
    private EJBDatabaseQuery ejbdb;
    public void doGet(HttpServletRequest request,  HttpServletResponse response)
    {
	doPost(request, response);
    }

    public void doPost(HttpServletRequest request,  HttpServletResponse response) 
    {
	try {
	    response.setContentType("text/html");
	    HttpSession session = request.getSession(true);
	    PrintWriter out  = response.getWriter();
	    String user_ip   = request.getRemoteAddr();
	    //String call_path = request.getServletPath();
	    String call_path = request.getContextPath()+request.getServletPath();
	    String mid = (String)request.getAttribute("mid");
	    if(mid == null) {
		System.out.println("PageColorServlet:Error:[mid==null]");
		return;
	    }

	    Hashtable achs = (Hashtable)request.getAttribute("achs");
	    if(achs == null) {
		return;
	    }

	    int read_level     = Integer.parseInt((String)achs.get("read_level"));
	    int read_age       = Integer.parseInt((String)achs.get("read_age"));
	    int post_level     = Integer.parseInt((String)achs.get("post_level"));
	    int post_age       = Integer.parseInt((String)achs.get("post_age"));

	    boolean manager  = (Boolean.valueOf((String)achs.get("show_manager"))).booleanValue();
	    boolean admin    = (Boolean.valueOf((String)achs.get("show_admin"))).booleanValue();

	    String action = request.getParameter("aid");

	    PageColorBean pcbean = new PageColorBean ();

	    //================================================================
	    // change color setting (cookie set in IndexServlet)
	    //================================================================

	    if(action == null || action.equals("0")) {
		String pc_id = request.getParameter("pc_id");
		if(pc_id == null) {
		    pc_id = (String)request.getAttribute("page_color_id");
		}
		out.println(pcbean.setPageColor(call_path, mid, pc_id, manager, admin));
	    }

	    //================================================================
	    // Edit color table 
	    //================================================================

	    if(action != null && action.equals("4-1")) {
		out.println(pcbean.editPageColor(request, call_path, mid, "4-1", "0"));
	    }
	}
	catch(IOException e) {
	    System.out.println("PageColorServlet:Error:901:"+e);
	    return;
	}
	catch(Exception e) {
	    System.out.println("PageColorServlet:Error:902:"+e);
	    return;
	}
    }
}






